/*
 * NewAccountDialog.java
 *
 * Created on May 5, 2007, 1:25 AM
 */
package choreganizer;

import javax.swing.*;
import choreganizer.accounts.ScheduleFactory.FactoryType;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;

/**
 *
 * @author  daelus
 */
public class NewAccountDialog extends javax.swing.JDialog {
    // Variable to hold our selected factory type
    public FactoryType _SelectedType;

    /** Creates new form NewAccountDialog
     * @param parent
     * @param modal s
     */
    public NewAccountDialog(java.awt.Frame parent, boolean modal) {
	super(parent, modal);
	initComponents();

	// Create radio buttons for each factory type
	for (FactoryType type : FactoryType.values()) {
	    JRadioButton radioButton = new JRadioButton(type.toString(), false);
	    radioButton.setAction(new SelectionAction(type));
	    _RadioButtonGroup.add(radioButton);
	    _Panel.add(radioButton);
	}
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _RadioButtonGroup = new javax.swing.ButtonGroup();
        _ContinueButton = new javax.swing.JButton();
        _CancelButton = new javax.swing.JButton();
        _Panel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Create a new account");
        setResizable(false);

        _ContinueButton.setText("Continue");
        _ContinueButton.setEnabled(false);

        _CancelButton.setAction(new CloseDialogAction());
        _CancelButton.setText("Cancel");

        _Panel.setBorder(javax.swing.BorderFactory.createTitledBorder("Account Type"));
        _Panel.setLayout(new javax.swing.BoxLayout(_Panel, javax.swing.BoxLayout.Y_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(_ContinueButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(_CancelButton))
                    .addComponent(_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_CancelButton)
                    .addComponent(_ContinueButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
	java.awt.EventQueue.invokeLater(new Runnable() {

	    @Override
	    public void run() {
		new NewAccountDialog(new javax.swing.JFrame(), true).setVisible(true);
	    }
	});
    }

    public void CancelAccount() {
	this.setVisible(false);
	this.dispose();
    }

    class CloseDialogAction extends AbstractAction {

	public CloseDialogAction() {
	    super("Cancel", null);
	    putValue(SHORT_DESCRIPTION, "Cancel account creation");
	    putValue(MNEMONIC_KEY, null);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
	    CancelAccount();
	}
    }

    class SelectionAction extends AbstractAction {

	private FactoryType type;

	public SelectionAction(FactoryType type) {
	    super(type.toString(), null);
	    this.type = type;
	    putValue(SHORT_DESCRIPTION, "Create account");
	    putValue(MNEMONIC_KEY, null);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
	    _SelectedType = type;
	    _ContinueButton.setEnabled(true);
	}
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _CancelButton;
    public javax.swing.JButton _ContinueButton;
    private javax.swing.JPanel _Panel;
    public javax.swing.ButtonGroup _RadioButtonGroup;
    // End of variables declaration//GEN-END:variables
}
